
<template>
<div class="mui-content" >

  <div class="unitWrapper">
    <div class="appendTitle">填写新增单位</div>
    <div class="unit">
      <div class="unitTitle"> 所属区县：</div>
      <input type="text" class="unitwork unitwork2" @click="choose" v-model="addUnit">
    </div>
    <div style="background: white">
    <ul class="ul">
      <li class="li" v-for="(item,index) in dataList" :key="index" @click.stop="city(dataList[index],index1)">{{item.Name}}</li>
    </ul>
  </div>
    <div v-show="showMe">

      <div class="unit">
        <div class="unitTitle"> 单位名称：</div>
        <input type="text" class="unitwork" v-model="addUnitName">
      </div>
      <div class="unit ">
        <div class="unitTitle"> 说明：</div>
        <div class="unitwork1">此功能用于用户在选择单位时系统中无此单位,需增加单位的基础设置，由用户提出增加申请,由区县,市州,省级管理员确认后增加.</div>
      </div>
    </div>

  </div>
  <div class="unitAppend" v-show="showMe">
    <div class="appendTitle">申请历史</div>
    <div  class="contentWrapper" ref="contentWrap" >
      <div class="contentWrapper1">

   <ul v-for="(unitData2,index) in unitData1" :key="index">
     <li class="historyTitle"> <span>记录-{{index+1}}</span></li>
     <li v-for="(item,index) in unitData2 " :key="index"><span>{{item.title}}</span><span>{{item.text}}</span></li>
   </ul>
      </div>
    </div>
    <div class="bind mui-text-center" @click="onSubmit" >
      提交
    </div>
  </div>
  <!--错误提醒-->
  <transition name="fade">
    <Prompt
      title="错误"
      :msg=mistakeMsg
      confirm="确定"
      v-on:confirm1="confirm2($event)"
      v-if="mistake"
    >
    </Prompt>
  </transition>
</div>
</template>

<script>
  import BScroll from 'better-scroll'
  import  Prompt from '@components/common/Prompt.vue'
    export default {
        name: "AppendUnit.vue",
      components:{
          Prompt
      },
      data(){
          return{
            UserId:'',
            mistake:false,
            mistakeMsg:'',
            unitData1:[],
            unitData:[
              {title:'申请时间：',text:'无'},
              {title:'单位名称：',text:'无'},
              {title:'区县：',text:'无'},
              {title:'州市：',text:'无'},
              {title:'处理时间：',text:'无'},
              {title:'结果：',text:'无'},
              {title:'说明：',text:'无'},
              ],
            dataList:[],
            index1:0,
            addUnit:'',
            showMe:true,
            addUnitName:'',
            CityName:'',
            CitySN:'',
            DistrictSN:'',
            DistrictName:'',
            phone:'',
            scroll:{}


      }
      },
      created(){
          if(localStorage.getItem('myPhone')){
            this.phone=localStorage.getItem('myPhone');
          }else if(sessionStorage.getItem('myRegphone')){
             this.phone=sessionStorage.getItem('myRegphone')
          }

        let me=this
        me.$Global.zcServer.Post({
          IsNeedLogin:'false',
          Paras:{
            //UserId:me.$Global.UserId ,
            Name:'Vue_CourseResource',
            Action:'Ext_ApplyByRegPhone',
            Data:{
              RePhone:me.phone
            }
          },
          Callback:me.cbHistory,
          Scope:me
        });

      },
      methods:{
          choose(){
            this.dataList=[];
            this.addUnit='';
            this.showMe=false;
            let me=this
            me.$Global.zcServer.Post({
              IsNeedLogin:'false',
              Paras:{
                UserId:me.$Global.UserId ,
                Name:'Vue_WorkUnit',
                Action:'City',
                Data:{
                  SN:''
                }
              },
              Callback:me.Callback_City,
              Scope:me
            });
          },
        city(index,index1){
          this.index1=index1+1
          if(this.addUnit==''){
            this.addUnit=index.Name;
            this.CityName=index.Name;
            this.CitySN=index.SN

          }else {
            this.addUnit=this.addUnit+"-"+index.Name;
            this.DistrictName=index.Name;
            this.DistrictSN=index.SN
          }
          let me=this
          me.$Global.zcServer.Post({
            IsNeedLogin:'false',
            Paras:{
              UserId:me.$Global.UserId ,
              Name:'Vue_WorkUnit',
              Action:'Xian',
              Data:{
                CitySN:index.SN
              }
            },
            Callback:me.Callback_Xian,
            Scope:me
          });

          if(index1==1){
            me.index1=0;
            me.showMe=true;
            return
          }
        },
        onSubmit(){
          let me=this
          me.$Global.zcServer.Post({
            IsNeedLogin:'true',
            Paras:{
              UserId:me.$Global.UserId ,
              Name:'Vue_CourseResource',
              Action:'Ext_WorkUnitSubmit',
              Data:{
                Name:me.addUnitName,
                CitySN:me.CitySN,
                CityName:me.CityName,
                DistrictSN:me.DistrictSN,
                DistrictName:me.DistrictName
              }
            },
            Callback:me.cb_WorkUnitSubmit,
            Scope:me
          });
        },
        confirm2(){
            this.mistake=false
        },
        /*回調*/
        Callback_City(resJson,scope){
          console.log(resJson)
          this.dataList=resJson.data
        },
        Callback_Xian(resJson,scope){
          console.log(resJson)
          this.dataList=resJson.data
        },
        cbHistory(resJson,scope){
          console.log("申请进度返回")
          console.log(resJson)
          if(!resJson.success){
            this.mistake=true;
            this.mistakeMsg=resJson.msg
          }else {

            if (resJson.data.length==0) {
              let unitData2=[
                {title:'申请时间：',text:'无'},
                {title:'单位名称：',text:'无'},
                {title:'区县：',text:'无'},
                {title:'州市：',text:'无'},
                {title:'处理时间：',text:'无'},
                {title:'结果：',text:'无'},
                {title:'说明：',text:'无'},
              ]
              this.unitData1.push(unitData2)

            }else {
              for (let i = 0; i < resJson.data.length; i++) {
                let unitData2=[
                  {title:'申请时间：',text:'无'},
                  {title:'单位名称：',text:'无'},
                  {title:'区县：',text:'无'},
                  {title:'州市：',text:'无'},
                  {title:'处理时间：',text:'无'},
                  {title:'结果：',text:'无'},
                  {title:'说明：',text:'无'},
                ]
                let historyData = resJson.data[i];
                // this.formatDate(historyData.doDate)
                console.log(historyData.doDate)
                console.log(this.Test(historyData.ApplyDate))
                // if(historyData){
                unitData2[0].text = this.Test(historyData.ApplyDate)
                unitData2[1].text = historyData.Name
                unitData2[2].text = historyData.DistrictName
                unitData2[3].text = historyData.CityName
                unitData2[4].text = this.Test(historyData.doDate)
                if(unitData2[4].text=='1950-4-24'){
                  unitData2[4].text=''
                }
                unitData2[5].text = historyData.Result
                unitData2[6].text = historyData.doRemark
                this.unitData1.push(unitData2)
              }
            }
          }
          // }

          this.$nextTick(()=>{
            this.scroll = new BScroll(this.$refs.contentWrap, {
              probeType: 3,
              click:true,
              scrollX: false
            });
          })
        },
        cb_WorkUnitSubmit(resJson,scope){
          console.log(resJson)
          if(resJson.success==false){
            this.mistake=true;
            this.mistakeMsg=resJson.msg
          }else {
           this.$router.push('/PaperApply')
          }

        },
      /*转化时间格式*/
        formatDate(dt) {
          let year = dt.getFullYear();
          let month = dt.getMonth() + 1;
          let date = dt.getDate();
          return year + "-" + month + "-" + date
        },
        Test(time) {
          let t= time.slice(6, 19);
          let NewDtime = new Date(parseInt(t));
          return this.formatDate(NewDtime);
        },
    }

    }
</script>

<style scoped>
  /*地区*/
  .ul{
    width:70% ;
    margin-left: 90px;
    text-align: center;
    background: white;

  }
  .ul .li{
    width: 100%;
    height: 30px;
    line-height: 30px;
    border-bottom: 1px solid gainsboro;
  }
.unit{
display: flex;
  height: 2.5rem;
  line-height: 2.5rem;
  width: 100%;
  background: white;
  padding-left: 2%;
}
 .mui-content .unitTitle{
    flex: 0 0 85px;
  }
.mui-content .unitwork{
    flex: 1;
    height: 1.9rem;
    margin-top: 0.3rem;
  }
.mui-content .unitwork2{
    background: url('../../assets/img/jiantou.png') no-repeat 95% 50%;
  }
.mui-content .unit:last-child{
  padding: 2%;
  height: auto;
  /*line-height: 2rem;*/

}
.mui-content .unit .unitwork1{
  font-size: 0.9rem;
  line-height: 1.5rem;
  color: red;
}
.mui-content .unitAppend{
    margin-top: 10px;
padding-bottom: 40px;
  background: white;
  }
.mui-content .appendTitle{
  text-align: center;
  background: rgba(93, 194, 240, 1);
  color: white;
  height: 40px;
  line-height: 40px;
  border-bottom: 1px solid gainsboro;

}
.mui-content .unitAppend li{
  /*padding-left: ;*/
  width: 100%;
  display: flex;
  padding: 5px 2%;
  border-bottom: 1px solid gainsboro;

}
.mui-content .unitAppend li span:first-child{
flex:  0 0 90px;

}
.mui-content .unitAppend li span:last-child{
  flex: 1;
}

  .mui-content .bind{
    width: 88%;
    height: 40px;
    background-color:rgba(93, 194, 240, 1);
    color: white;
    margin:  auto;
    line-height: 40px;
    margin-top: 30px;
    border: none;
    border-radius: 4px;

  }
  .contentWrapper{
    position: relative;
    width: 100%;
    height: 255px;
    overflow: hidden;
  }
  .historyTitle{
    width: 100%;
    /*text-align: center !important;*/
    /*padding-left: 45% !important;*/
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

  }
  .historyTitle span{
    display: inline-block !important;
    width: 100%;
    text-align: center;
  }
</style>
